package com.wondedDream.controller.admin;

import com.wondedDream.model.Practice;
import com.wondedDream.service.PracticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminPracticeController")
@RequestMapping("/api/practice")
@Api(description = "管理端-练习信息")
public class PracticeController {

    @Autowired
    private PracticeService practiceService;

    // 创建新的课程
    @PostMapping("/")
    @ApiOperation(value = "创建新的练习")
    public Practice createPractice(@RequestBody Practice practice) {
        return practiceService.savePractice(practice);
    }



    // 根据课程id删除课程信息
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据课程id删除练习信息")
    public void deletePractice(@PathVariable Integer id) {
        practiceService.deletePractice(id);
    }


    // 根据课程id修改课程信息
    @PutMapping("/{id}")
    @ApiOperation(value = "根据课程id修改练习信息")
    public Practice updatePractice(@PathVariable Integer id, @RequestBody Practice practice) {
        practice.setId(id);
        return practiceService.updatePractice(practice);
    }

    // 获取课程信息
    @GetMapping("/{id}")
    @ApiOperation(value = "获取练习信息")
    public Practice getPracticeById(@PathVariable Integer id) {
        return practiceService.getPracticeById(id);
    }

    // 获取某一分类下的课程列表
    @GetMapping("/byCategory/{categoryId}")
    @ApiOperation(value = "获取某一分类下的练习列表")
    public List<Practice> getCoursesByCategoryId(@PathVariable Integer categoryId) {
        return practiceService.getPracticesByCategoryId(categoryId);
    }

    // 获取所有课程列表
    @GetMapping("/")
    @ApiOperation(value = "获取所有练习列表")
    public List<Practice> getAllPractices() {
        return practiceService.getAllPractices();
    }

    // 创建新的模考问题
    @PostMapping("/createPracticeQuestionByFileJson")
    @ApiOperation(value = "根据文件导入模考题库")
    public String createPracticeQuestionByFileJson() {
        practiceService.createPracticeQuestionByFileJson();
        return "success";
    }
}